#ifndef SHARED
#define SHARED

#include <thread>
#include <future>
#include <fstream>
#include "database.h"
#include "json.h"
#include "messagequeue.h"
#include "httplib.h"
#include "threadpool.h"

/********************************共用枚举类型********************************/
// 返回值类型：表征某个逻辑的处理结果

enum class ReqType {
    STATIC,  // /static***
    PUBLIC,  // /public***
    REGISTER,   // /register***
};

enum status
{
    SUCCESS,
    FAIL,
    TIMEOUT,
    ACCOUNT_EXIST,
    USERNAME_EXIST,
    EMAIL_EXIST,
};

/********************************共用数据类型********************************/
// 请求消息结构
struct RequestMessage
{
    ReqType type;
    std::shared_ptr<httplib::Request> req;
    httplib::Response* res;
    std::shared_ptr<std::promise<void>> completion_promise;
};

// 响应消息结构
struct ResponseMessage
{
    httplib::Response *res;
    std::shared_ptr<std::promise<void>> completion_promise;
};

/********************************共用全局变量********************************/
extern MessageQueue<RequestMessage> msgrout2authMQ;      /*消息路由线程发送给授权管理线程的消息队列*/
extern MessageQueue<RequestMessage> msgrout2serviceMQ;   /*消息路由线程发送给业务线程的消息队列*/
extern MessageQueue<ResponseMessage> process2responseMQ; /*各个处理线程发送给消息响应线程的消息队列*/

extern std::string rootDir;     /*数据根目录*/
extern Database db;             /*数据库*/
/********************************共用函数********************************/
extern status getFirstSegment(const std::string& str, std::string &firstSeg);

#endif